<!DOCTYPE html>
<html>
<head>
    <title>检测</title>
    <include file='public/head'>
    <style>
        table th, table td{text-align: center;}
        .ml-10 { margin-left: 10px; }
		.layui-icon{font-size: 14px !important;}
		.layui-form-label{ width: auto;}
		.layui-btn.layui-btn-sm .fa{ font-size: 14px !important;}
		.mr4{ margin-right: 4px;}
		.layui-form-item{ margin-bottom: 0px;}
		#check-item li{
			padding: 3px 5px;
			height: auto;
			line-height: 30px;
		}
    </style>
</head>
<body>
<div style="padding: 20px;">
	<ul id="check-item" style="list-style-type: none;">
		<li>正在检查安装信息，请稍后...</li>
	</ul>
</div>
</body>
<include file='public/scripts'>
<script type="text/javascript">
var sign = {
	item:0,
	complete:0,
	canInstall:true,
	message:'信息验证中，请稍后',
};	
$(document).ready(function(){
	$.post("{:cmf_plugin_url('ModuleConfig://InstallCheck/getCheckItem')}" , {} , function(data){
		sign.item = data.length;
		$.each( data , function( index , value ){
			check( index );
		});
	} ,'json');
});
var check = function( index ){
	$.ajax({
		url:'{:cmf_plugin_url("ModuleConfig://InstallCheck/check")}?index='+index,
		type:'POST',
		data:{
			param:{
				plugin_name:"{$data.plugin_name|default=''}",
				module_name:"{$data.module_name|default=''}",
				id:"{$data.id|default=''}"
			}
		},
		success:function( data ){
			result = JSON.parse(data);
			showMessage( result );
		},
		complete:function(){
			sign.complete = sign.complete + 1 ;
		},
		error:function(){
			console.log(1000);
		}
	});
}
var clock = setInterval(function(){
	if( sign.item == sign.complete ){
		clearInterval( clock );
		if( sign.complete == sign.item ){
			if (sign.canInstall == true) {
				$('#check-item').append( '<li>插件安装成功</li>' );
			} else {
				$('#check-item').append( '<li>插件安装失败</li>' );
			}
		}
	}
},1000);
var showMessage = function( result ){
	let li = '';
	let icon  = "" ; 
	let color = '' ;
	$.each( result.message , function( index , value ){			 
		//警告信息 glyphicon glyphicon-info-sign
		//200是错误信息 201 是警告信息   
		switch( value.code )
		{
			case 200 : 
				icon = '<span style="green;" class="glyphicon glyphicon-ok"></span>';
				color = 'color:#18BC9C;';
			break;
			case 201 :
				icon = '<span style="color:orange;" class="glyphicon glyphicon-info-sign"></span>' ;
				color = 'color:orange;';
				if( value.operate != 'empty' ){
					sign.item = sign.item + 1;
					callback( value.operate );
				}
			break;
			default:
				//错误信息
				icon = '<span style="color:red;" class="glyphicon glyphicon-remove"></span>' ;
				color = 'color:red';
				sign.canInstall = false;
				sign.message = value.item + ":" + value.msg;
			break;
		}
		li = '<li style="'+color+'">'+ value.item + ':' + value.msg +icon+'</li>';
		$('#check-item').append( li );
	});
}
var callback = function ( action )
{
	console.log(action);
	$.post( action , {} ,function ( data ){
		showMessage( data );
		sign.complete = sign.complete + 1 ;
	} , 'json' );
}
</script>
</html>
